package ysq.xyg.web.controller;

import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.util.BaseConstant;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.sys.model.po.SysUser;
import ysq.xyg.web.model.po.WebBanner;
import ysq.xyg.web.model.po.WebConfig;
import ysq.xyg.web.model.vo.WebBannerVo;
import ysq.xyg.web.service.WebBannerService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 网站模块-网站banner图controller层
 *
 * @author shengQiang yu
 * @date 2019-6-5 21:55:58
 */
@RestController
public class WebBannerController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(WebBannerController.class);
    @Resource
    private WebBannerService webBannerService;

    private WebBanner webBanner;

    /**
     * 分页查询
     *
     * @param webBannerVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author shengQiang yu
     * @date 2019-6-5 21:55:58
     */
    @BaseLog(module = "网站模块",className = "网站banner图",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webBanner/page",method = RequestMethod.POST)
    public ReturnEntity page(HttpServletRequest request,WebBannerVo webBannerVo, int pageSize, int pageNum){
        SysUser sysUser=acceptCurrentUser(request);
        webBannerVo.setUserId(sysUser.getId());
        webBannerVo.setRemoveTag(BaseConstant.BASE_REMOVE_TAG_NORMAL);
        ReturnEntity returnEntity = webBannerService.page(webBannerVo,pageSize,pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-6-5 21:55:58
     */
    @RequestMapping(value = "/webBanner/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/web/webBannerUpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            webBanner = webBannerService.selectByPrimaryKey(id);
            view.addObject("webBanner", webBanner);
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-6-5 21:55:58
     */
    @BaseLog(module = "网站模块",className = "网站banner图",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webBanner/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return webBannerService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param webBannerVo Vo对象
     * @author shengQiang yu
     * @date 2019-6-5 21:55:58
     */
    @BaseLog(module = "网站模块",className = "网站banner图",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webBanner/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,WebBannerVo webBannerVo){
        return webBannerService.addOrUpdate(webBannerVo,acceptCurrentUser(request));
    }
}